#define ledverte    PORTB.RB5
#define ledjaune    PORTB.RB4
#define ledbleue    PORTB.RB3
#define ledblanche    PORTB.RB2
#define ledrouge    PORTB.RB1

#define bblanc    PORTC.RC1
#define bjaune    PORTC.RC0
#define bvert    PORTC.RC2
#define bbleu    PORTC.RC3


unsigned short current_duty2, pourcent ;
void train1000(void);
void train200(void);
void train100(void);

void main() {

  TRISA = 0b00000000;           // set direction to be output
  TRISB = 0b00000000;           // set direction to be output
  TRISC = 0b00001111;           // set direction to be output
  /*PORTA = 0x00;
  PORTB = 0x00;
  PORTC = 0x00;   */


  
  /*PWM2_Init(5000);                    // Initialize PWM2 module at 5 kHz
  current_duty2 = 0; 
  pourcent=0;                // initial value for current_duty1
  PWM2_Start();                       // start PWM2

  PWM2_Set_Duty(current_duty2);       // Set current duty for PWM2
  */


  do {
  
     train100 ();
     train200 ();
  
  /*
     ledverte = 1;
     ledjaune = 1;
     //ledbleue = 1;
     ledblanche = 1;
     ledrouge = 1;

     
     //if (bjaune) {                    // button on bjaune pressed
      Delay_ms(50);
      //pourcent += 20;
      //current_duty2 = (unsigned short)((pourcent*255)/100);
      current_duty2 += 10;                                                                       // increment current_duty2
      if (current_duty2 >= 255){current_duty2 = 0;pourcent=0;}
      PWM2_Set_Duty(current_duty2);
      if (current_duty2 == 0){Delay_ms(1000);}
     //}


    */


    /*LATA = 0xff;
    LATC = 0xf0;
    ledverte = 1;
    ledjaune = 1;
    ledbleue = 1;
    ledblanche = 1;
    //ledrouge = 1;
    Delay_ms(1000);    // 1 second delay

    LATA = 0;
    //LATC = 0;
    ledverte = 0;
    ledjaune = 0;
    ledbleue = 0;
    ledblanche = 0;
    //ledrouge = 0;
    Delay_ms(1000);    // 1 second delay
    if (bjaune == 1){ledrouge = 1;}else{ledrouge = 0;}   */

    
  } while(1);          // Endless loop
}
void train1000 (void){
     const unsigned long delay = 1000;
     ledverte = 1;
     ledjaune = 0;
     ledbleue = 0;
     ledblanche = 0;
     ledrouge = 0;
     Delay_ms (delay);

     ledverte = 0;
     ledjaune = 1;
     ledbleue = 0;
     ledblanche = 0;
     ledrouge = 0;
     Delay_ms (delay);

     ledverte = 0;
     ledjaune = 0;
     ledbleue = 1;
     ledblanche = 0;
     ledrouge = 0;
     Delay_ms (delay);

     ledverte = 0;
     ledjaune = 0;
     ledbleue = 0;
     ledblanche = 1;
     ledrouge = 0;
     Delay_ms (delay);

     ledverte = 0;
     ledjaune = 0;
     ledbleue = 0;
     ledblanche = 0;
     ledrouge = 1;
     Delay_ms (delay);


}
void train200 (void){
     const unsigned long delay = 200;
     ledverte = 1;
     ledjaune = 0;
     ledbleue = 0;
     ledblanche = 0;
     ledrouge = 0;
     Delay_ms (delay);

     ledverte = 0;
     ledjaune = 1;
     ledbleue = 0;
     ledblanche = 0;
     ledrouge = 0;
     Delay_ms (delay);

     ledverte = 0;
     ledjaune = 0;
     ledbleue = 1;
     ledblanche = 0;
     ledrouge = 0;
     Delay_ms (delay);

     ledverte = 0;
     ledjaune = 0;
     ledbleue = 0;
     ledblanche = 1;
     ledrouge = 0;
     Delay_ms (delay);

     ledverte = 0;
     ledjaune = 0;
     ledbleue = 0;
     ledblanche = 0;
     ledrouge = 1;
     Delay_ms (delay);


}
void train100 (void){
     const unsigned long delay = 100;
     ledverte = 1;
     ledjaune = 0;
     ledbleue = 0;
     ledblanche = 0;
     ledrouge = 0;
     Delay_ms (delay);

     ledverte = 0;
     ledjaune = 1;
     ledbleue = 0;
     ledblanche = 0;
     ledrouge = 0;
     Delay_ms (delay);

     ledverte = 0;
     ledjaune = 0;
     ledbleue = 1;
     ledblanche = 0;
     ledrouge = 0;
     Delay_ms (delay);

     ledverte = 0;
     ledjaune = 0;
     ledbleue = 0;
     ledblanche = 1;
     ledrouge = 0;
     Delay_ms (delay);

     ledverte = 0;
     ledjaune = 0;
     ledbleue = 0;
     ledblanche = 0;
     ledrouge = 1;
     Delay_ms (delay);
}